<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

<!-- 时间日期插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
    </div>
    <div class="page-title-border"></div>
</div>
<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">推广位ID: ${tgw}  ${userNickName}</span>
    </span>
   <span class="field-cont">
        <span class="field-cont-title">手机号:13752222222</span>
   </span>
   <span class="field-cont" id="toolbar">
   	
   </span>
    <span class="field-cont">
        <span class="field-cont-title">
        <a id="goBack" class="distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a></span>
    </span>
</div>
<%-- <div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">累计订单:${orderCount}</span>
        
    </span>
   <span class="field-cont">
        <span class="field-cont-title">有效累计订单:${totalMoney}</span>
   </span>
    
    <span class="field-cont">
        <span class="field-cont-title">累计总额:${effectOrderCount}</span>
    </span>
    <span class="field-cont">
        <span class="field-cont-title">累计建群数:${groupCount}</span>
    </span>
</div> --%>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="40%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <thead>
		    <tr>
		        <th>群名称</th>
				<th>群主</th>
		        <th>手机号</th>
		        <th>微信名称</th>
		        <th>微信Id</th>
		        <th>操作 </th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list',
		TGW_PERFORM_LIST :basePath + '${common_url}tgwGroup/list',
		TGW_PERFORM_VIEW : basePath + '${common_url}TgwPerformView?id=${tgwId}&groupId=${groupId}&userId=${userId}',
		ADD_TGW_GROUP_VIEW :basePath + '${common_url}addTgwGroupView?tgwId=${tgwId}&userId=${userId}&groupId=${groupId}&phone=${phone}',
		DEL_TGW_GROUP : basePath + '${common_url}tgwGroup/del',
		EDIT_TGW_GROUP_VIEW :basePath + '${common_url}editTgwGroupView?tgwId=${tgwId}&userId=${userId}&groupId=${groupId}&phone=${phone}'
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:addTgwGroupView'],
		});
        
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#${name_english}Version').val('');
        	$('#startTime').val(''); 
        	$('#stopTime').val('');
        	reloadTable();
        });
        createTable();
        $('#backBtn,#goBack').on('click',backMain);
      	//新建
        $('#toolbar').on('click', 'a[data-permit="${name_english}:addTgwGroupView"]', function() {
        	window.location.href = CONST_URL.ADD_TGW_GROUP_VIEW; 	  	
		});
      	
      	//编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:editTgwGroupView"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.EDIT_TGW_GROUP_VIEW+ '&id=' + id;
        });	
      	
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:delTgwGroup"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL_TGW_GROUP + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
    });
    function backMain() {
    	window.location.href = CONST_URL.TGW_PERFORM_VIEW;
    }
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"startTime": $('#startTime').val(),
                	"endTime": $('#endTime').val(),
                	"orderCount": trimSpace($('#orderCount').val()),
                	"money": trimSpace($('#totalMoney').val()),
                	"groupCount": trimSpace($('#groupCount').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.TGW_PERFORM_LIST,
    			param: {
    				"tgwId": ${tgwId}
            	
    			} 
    		},
    		columns: [
    			{
   		    	 field: 'id',
   		    	 hidden:true
   		     	},
    		     {
    		    	 field: 'groupName'
    		     },
    		     {
    		    	 field: 'groupMain'
    		     },{
    		    	 field: 'groupPhone'
    		     },{
    		    	 field: 'wxName'
    		     },{
    		    	 field: 'wxId'
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 return $.funcbar({
    		    			 data: permission,    //请求的数据
    		    			 type: 'text',     //类型
    		    			 display: 2,    //显示数量
    		    			 permit: ['${name_english}:editTgwGroupView','${name_english}:delTgwGroup'] //需要的权限按钮
    		    		 });
    		    	 }
    		    }
    	    ]
    	});
    }
</script>
</body>
</html>